package com.system.healthproject.model.admin.controller;

import com.system.healthproject.bean.*;
import com.system.healthproject.common.ApiResult;
import com.system.healthproject.model.admin.service.HospitalService;
import com.system.healthproject.pojo.Department;
import com.system.healthproject.pojo.Hospital;
import com.system.healthproject.utils.DateUtils;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 *   医院信息管理
 */
@Controller
@Api(value = "医院信息管理" ,tags = "后端-医院数据接口api")
@ApiResponses({
        @ApiResponse(code=400,message="请求参数不完整或者错误"),
        @ApiResponse(code=404,message="找不到页面"),
        @ApiResponse(code=415,message="请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串"),
        @ApiResponse(code=500,message="后台服务错误")
})
@RequestMapping("/admin/hospital")
public class HospitalController {

    @Autowired
   private HospitalService hospitalService;

    /**
     *   多条件查询医院列表
     */

    @RequestMapping(value = "/conditionSelect" ,method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    @ApiOperation(value = "查询医院列表（包括条件查询）接口已调用",notes = "可以多条件查询",httpMethod = "post")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "hospitalName",value = "医院名称",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "hospitalLevel",value = "医院等级",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "hospitalAddress",value = "医院地址",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "hospitalNickname",value = "医院别称",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "createTime",value = "创建时间",paramType = "query",dataType = "Date",required = false),
            @ApiImplicitParam(name = "currentPage",value = "当前页",paramType = "query",dataType = "int",required = true),
            @ApiImplicitParam(name = "limit",value = "每页显示数据条数",paramType = "query",dataType = "int",required = true),
    })
    public  ApiResult<PagesBean<ResultHospital>> conditionSelect(
            String hospitalName,String hospitalLevel,String hospitalAddress,String hospitalNickname,
            String createTime,Integer currentPage,Integer limit){
            List<ResultHospital> lsit = hospitalService.selectAllHospital(hospitalName,hospitalLevel,hospitalAddress,hospitalNickname,createTime,currentPage,limit);
            Integer count = hospitalService.countHospital(hospitalName,hospitalLevel,hospitalAddress,hospitalNickname,createTime,currentPage,limit);
        System.out.println(count);
            PagesBean<ResultHospital> pagesBean = new PagesBean<>();
            pagesBean.setData(lsit);
            pagesBean.setNowsPage(currentPage);
            pagesBean.setPageSize(limit);
            pagesBean.setDataCount(count);
        return ApiResult.successWithData("成功",pagesBean);
    }


    /**
     * 删除医院
     */
    @RequestMapping(value = "/deleteHospital" ,method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    @ApiOperation(value = "删除医院（接口已调用）",notes = "删除医院",httpMethod = "post")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "hospitalId",value = "医院ID",paramType = "query",dataType = "int",required = true),
    })
    public  ApiResult deleteHospital(Integer hospitalId){
        String msg = hospitalService.deleteHospital(hospitalId);
        return ApiResult.successWithData(msg);
    }


    /**
     *   编辑医院
     */

    @RequestMapping(value = "/updateHospital" ,method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    @ApiOperation(value = "修改医院信息（接口已调用）",notes = "编辑医院",httpMethod = "post")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "hospitalId",value = "医院ID",paramType = "query",dataType = "int",required = true),
            @ApiImplicitParam(name = "hospitalName",value = "医院名称",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "hospitalLevel",value = "医院等级",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "hospitalAddress",value = "医院地址",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "hospitalNickname",value = "医院别称",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "createTime",value = "创建时间",paramType = "query",dataType = "Date",required = false),
    })
    public  ApiResult updateHospital(
            Integer hospitalId,
            String hospitalName,
            String hospitalLevel,
            String hospitalAddress,
            String hospitalNickname,
            String createTime){

        String msg = hospitalService.
                updateHospital(hospitalId,hospitalName,
                        hospitalLevel,hospitalAddress,hospitalNickname,createTime);
        return ApiResult.successWithData(msg);
    }


    /**
     * 查询医院id 医院名称
     */
    @RequestMapping(value = "/selectHospitalIdName" ,method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    @ApiOperation(value = "查询所有医院ID和名称(接口已调用)",notes = "查询所有",httpMethod = "post")
    public  ApiResult<List<ResultHospitalIdName>> selectHospitalIdName(){
        List<ResultHospitalIdName> list =hospitalService.selectHospitalIdName();
        for (ResultHospitalIdName resultHospitalIdName : list) {
            System.out.println(resultHospitalIdName);
        }
        return ApiResult.successWithData("成功",list);
    }


    /**
     * 新增医院
     * @param addHospitalParameter 要添加的医院信息
     * @return
     */
    @RequestMapping(value = "/addHospital" ,method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    @ApiOperation(value = "新增医院(接口已调用)",notes = "新增医院",httpMethod = "post",response = ApiResult.class)
    public  ApiResult addHospital(@RequestBody @ApiParam(name = "hospital",value = "医院信息参数",required = false) AddHospitalParameter addHospitalParameter){
        String msg = hospitalService.addHospital(addHospitalParameter);
        return ApiResult.successWithData(msg);
    }

    /**
     * 查看医院详细信息(根据医院id查询)
     */
    @RequestMapping(value = "/selectByIDHospital" ,method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    @ApiImplicitParam(name = "hospitalId",value = "医院ID",paramType = "query",dataType = "int",required = true)
    @ApiOperation(value = "查看医院详情(接口已调用)",notes = "查看医院详情",httpMethod = "post")
    public ApiResult<List<ResultHospitalInfo>> selectByIDHospital(Integer hospitalId){
        List<ResultHospitalInfo> resultHospitalInfos = hospitalService.selectByIdHospital(hospitalId);
        return new ApiResult(200,"成功",resultHospitalInfos);
    }



}
